runOnStartup(async runtime => {
    runtime.addEventListener("tick", () => tick())
    runtime.getLayout("MainLevel").addEventListener("afterlayoutstart", () => init())
});
function tick() {
    if (runtime.layout.name != "MainLevel") return;
    //playerTochDuckEvent.TouchDuck()
    playerTochDuckEvent.heartZore()
    playerTochDuckEvent.playerMaskZBiindBiBoaradZ()
}
function init() {
    playerTochDuckEvent.TouchDuckByevent()
}
globalThis.playerTochDuckEvent = {
    playerMaskZBiindBiBoaradZ:function(){
        let Mask =runtime.objects.PlayerCollision.getFirstInstance()
        let Billboard =runtime.objects.PlayerBillboard.getFirstInstance()
        Mask.zElevation=Billboard.zElevation
    },
    TouchDuckByevent: function () {
        window.addEventListener("playerColliDuck", (e) => {
            /**@type {ISpriteInstance} */
            let getduck = e.detail[0]
            /**@type {ISpriteInstance} */
            let playerMask =runtime.objects.PlayerCollision.getFirstInstance()
            if(playerMask.zElevation>getduck.zElevation) return
            if (playerSelfdata.playerHeart > 0) {
                console.error("event:PlayerTouchDuck")
                playerSelfdata.playerHeart -= 1
                UIplayerHeartMissHeart.missHeart()
                Camear_CameraShke.shake()
                let effgetHurt =runtime.objects.eff_playerTouchDuck.createInstance("eff",playerMask.x,playerMask.y,true)
                effgetHurt.zElevation=30
            }
        })
    },
    TouchDuck: function () {
        /**@type {ISpriteInstance} */
        let player = runtime.objects.PlayerCollision.getFirstInstance()
        /**@type {I3DShapeInstance} */
        let PlayerBillboard = runtime.objects.PlayerBillboard.getFirstInstance()
        player.zElevation = PlayerBillboard.zElevation
        for (let getDuck of runtime.objects.DuckObject.instances()) {
            if (player.testOverlap(getDuck) && player.zElevation == getDuck.zElevation && player.instVars.inTouchDuck == 0) {
                player.instVars.inTouchDuck = 1
                setTimeout(function () {
                    player.instVars.inTouchDuck = 0
                }, 500)
                /**@type {ISpriteInstance} */
                let duck = getDuck
                if (playerSelfdata.playerHeart > 0) {
                    console.log("get hurt")
                    playerSelfdata.playerHeart -= 1
                    UIplayerHeartMissHeart.missHeart()
                    Camear_CameraShke.shake()
                }
            }
        }
    },
    heartZore: function () {
        if (playerSelfdata.playerHeart <= 0) {
            LoseGameLayerEffect.showEffect()
            /**@type {ILayout} */
            let Gamelayout = runtime.getLayout("MainLevel")
            /**@type {ILayer} */
            let loseLayer = Gamelayout.getLayer("loseHUD")
            /**@type {ISpriteInstance} */
            let player = runtime.objects.PlayerCollision.getFirstInstance()
            /**@type {I8DirectionBehaviorInstance} */
            let behaviors = player.behaviors['8Direction']
            /**@type {ISpriteInstance} */
            let PlayerAnimations = runtime.objects.PlayerAnimations.getFirstInstance()
            let PlayerBillboard = runtime.objects.PlayerBillboard.getFirstInstance()
            loseLayer.isVisible = true
            behaviors.isEnabled = false
            PlayerAnimations.setAnimation("lose")
            PlayerBillboard.zElevation = 0
        }
    }
}
export default playerTochDuckEvent